package org.example.springboot.mybatis.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.springboot.mybatis.mapper.UserMapper;
import org.example.springboot.mybatis.po.User;
import org.example.springboot.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(String id) {
        return userMapper.findById(id);
    }

    @Override
    public Map<String, Object> getUsers(int pageNum) {
        PageHelper.startPage(pageNum, 5);
        Page<User> userPage = (Page<User>)userMapper.findAll();
        Map<String, Object> results = new HashMap<>();
        results.put("total", userPage.getTotal());
        results.put("rows", userPage.getResult());
        return results;
    }
}
